﻿//继承原型
function inheritPrototype(subType, superType) {
    var F = function() {};
    F.prototype = superType.prototype;
    var prototype = new F(); //创建对象
    prototype.constructor = subType;  //增强对象
    subType.prototype = prototype;   //指定对象
}

function SuperType() {
    EIAP.apply(this, arguments[0]);
}
SuperType.prototype.colors = ["red", "blue", "green"];
SuperType.prototype.name = "superName";
SuperType.prototype.sayName = function () {
    alert(this.name);
};


function SubType() {
    SuperType.apply(this, arguments);
}
inheritPrototype(SubType, SuperType);
SubType.prototype.sayAge = function () {
    alert(this.age);
};

window.EIAP = {
    //给o扩充defaults对象中的属性，给o扩充c对象中的属性
    apply: function (o, c, defaults) {
        if (defaults) {
            EIAP.apply(o, defaults);
        }
        if (o && c && typeof c == 'object') {
            for (var p in c) {
                o[p] = c[p];
            }
        }
        return o;
    },
    //覆盖：给origclass的原型prototype扩充overrides对象中的属性
    override: function (origclass, overrides) {
        if (overrides) {
            var p = origclass.prototype;
            EIAP.apply(p, overrides);
            //如果overrides存在实例属性toString
            //这是为了适应IE早期版本，
            //IE早期版本的实现中存在一个BUG，即屏蔽不可枚举属性的实例属性不会出现在for-in循环中
            if (overrides.hasOwnProperty('toString')) {
                p.toString = overrides.toString;
            }
        }
    },
    extend: function (sb, sp, overrides) {
            if (typeof sp == 'object') {
                overrides = sp;
                sp = sb;
                sb = overrides.constructor != Object.prototype.constructor
                    ? overrides.constructor
                    : function () {
                        sp.apply(this, arguments);
                    };
            }
            var F = function () {
            }, sbp, spp = sp.prototype;

            F.prototype = spp;
            sbp = sb.prototype = new F();
            sbp.constructor = sb;
            sb.superclass = spp;
            if (spp.constructor == Object.prototype.constructor) {
                spp.constructor = sp;
            }
     
            sbp.superclass = (function () {
                return spp;
            });
            EIAP.override(sb, overrides);
            sb.extend = function (o) {
                return EIAP.extend(sb, o);
            };
            return sb;
        }
};
function Field() {
    EIAP.apply(this, arguments[0]);
}
Field.prototype.school = "速传";



function TextField() {
    return new TextTest(arguments[0]);
}
TextTest = EIAP.extend(Field, {
    width: 160,
    height: 18,
    initComponent: function () {
        TextTest.superclass.initComponent.call(this);
    },
    onResize: function () {
        var g = this;
    }
});
